<?php

namespace App\Http\Controllers\Api;


use App\Models\Banner;
use App\Models\User;
use App\Http\Resources\Banner as BannerCollection;

use App\Http\Resources\User as UserCollection;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;




class IndexController extends ApiController
{




    public function __construct()
    {
        $this->middleware('auth:api')->only([
//            'index'
        ]);

    }


//    protected function guard(){
//
//        return Auth::guard('api');
//    }


    public function index(Request $request){

//        return $this->internalError('dddd');
//        return $this->notFond('ddd');
//        dd('in');



//        $user = Auth::user();
//        dd($user);
//
//        return Auth::user();

//        return $this->failed('ddddd',406);
//        dd('in');

//        $this->validate($request,[
//
//            'test1' => 'required',
//            'test2' => 'min:5'
//
//        ]);

        

//        dd(app());


//        app();

//        dd($this);

//        dd(Auth::guard('api'));

//        dd(Auth::attempt(['phone'=>'13115181221','password'=>'12345']));

//        dd($this->guard('api')->attempt([]));


//        dd(Auth::attempt('api'));

        return UserCollection::collection(User::limit(30)->get());

        return UserCollection::collection(User::paginate(Input::get('limit') ?: 20));

    }

    /**
     *
     *
     *
     * @api {get} /index/banner 首页的banner
     * @apiName Index banner
     * @apiGroup Index
     *
     * @apiVersion 1.0.0
     * @apiSampleRequest /api/index/banner
     *
     *
     */
    public function banner(){

        $banners = Banner::query()
            ->where('position',1)
            ->orderBy('recommend','desc')
            ->orderBy('index')
            ->get();

        return BannerCollection::collection($banners);


    }

}
